using UnityEngine;
using System.Collections;

public class Tutorial : MonoBehaviour {
	
	public int i;
	public TextMesh[] legends;
	public TextMesh actual;
	public TextMesh count;
	public int collected;
	private bool spacePress;
	public bool crossDoor;
	public GameObject skipText;
	public bool skip;
	private bool ready;
	
	void Start()
	{
		actual = legends[0];	

	}
	
	void Update () 
	{
		
		if(i == 0)
		{	
			count.text = collected+ "/2";

			if(collected >= 2)
			{
				deactiveText(1);
			}
		}
		
		if(i == 1)
		{
			count.gameObject.SetActive(false);
			deactiveText(2);
			gameObject.GetComponent<CharacterManager>().ActiveElement(CharacterManager.CharacterFunctions.DROP);
			i++;
		}
		
		if(i == 2)
		{
			if(Input.GetButtonDown("Jump") && !spacePress)
			{
				deactiveText(3);
				spacePress = true;
			}
		}
		
		if(i == 3)
		{
			deactiveText(4);
		}
		
		if(i == 4)
		{
			deactiveText(5);
		}
		
		if(i == 5)
		{
			if(!gameObject.GetComponent<CharacterManager>().specialCube)
			{
				i++;
			}
		}
		
		if(i == 6 || i == 7)
		{
			deactiveText(6);
			i++;
		}
		
		if(i == 8)
		{
			StartCoroutine("final");
			i++;
		}
		
	}
	
	void receivedColor()
	{
		if(collected++ < 2){}
	}

	void receivedDoor()
	{
		i++;	
	}
	
	void deactiveText(int index)
	{
		actual.gameObject.SetActive(false);
		actual = legends[index];
		actual.gameObject.SetActive(true);
	}
	void finishSpecialCube()
	{
		i++;	
	}
	
	IEnumerator final()
	{
		yield return new WaitForSeconds(5);
		deactiveText(7);
		yield return new WaitForSeconds(5);
		gameObject.AddComponent("SceneChange");
		if(gameObject.GetComponent<SceneChange>().existFade())
		{
			PlayerPrefs.SetString("Tutorial","Off");
			gameObject.GetComponent<SceneChange>().createFade("SelecaoLeveis",0.2f);
		}
	}
}
